﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Job.Logic.Personal;
using Job.Web.Framework;
using Job.Entity;

namespace Job.Web.userControls.Personal
{
    public partial class CreateResume : BaseCtrl
    {
        private int personAccountId
        {
            get
            {
                //后台管理员能通过后台为企业增加职位，所以在此处需要兼职企业ID从url或从Session中获取
                MySession session = new MySession();
                SessionPersonal sPerson = session.GetPersonalFromSession();
                if (null == sPerson)
                    return 0;
                else
                    return sPerson.PersonAccountid;
            }
        }

        PersonalLogic pl = new PersonalLogic();

        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            //户口所在地
            WebCommon.LoadLevelDropDownList(ddlHomeAddress1, ddlHomeAddress2, HomeAddressRlist,"","", Constants.DictionaryType.ADDR_CITY);

            //居住地
            WebCommon.LoadLevelDropDownList(ddlResideAddress1, ddlResideAddress2, ResideAddressRList, "","", Constants.DictionaryType.ADDR_CITY);
            JobPersonAccount account = pl.GetAccountByAccountid(personAccountId);
            if (account != null)
            {
                if (account.UserSex.HasValue)
                {
                    rblSex.SelectedValue = account.UserSex.Value.ToString();
                }

                txtCardId.Text = account.UserCard == null ? "" : account.UserCard;
                txtUserName.Text = account.UserName == null ? "" : account.UserName;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            JobPersonInfo info = new JobPersonInfo();
            info.UserName = txtUserName.Text.Trim();
            info.UserCard = txtCardId.Text.Trim();
            info.UserSex = Convert.ToInt32(rblSex.SelectedValue.Trim());
            info.ResumeName = txtResumeName.Text.Trim();
            info.ResideAddr = ddlResideAddress2.SelectedValue.Trim();
            info.HomeAddr = ddlHomeAddress2.SelectedValue.Trim();
            info.PersonAccountId = this.personAccountId;

            int accountId = new MySession().GetPersonalFromSession().PersonAccountid;
            JobPersonAccount account = pl.GetAccountByAccountid(accountId);
            info.LinkEmail = account.LinkEmail;
            info.LinkPhone = account.LinkPhone;

            pl.Insert(info);

            string url = WebCommon.GetApplicationPath(Request) + "Person/PersonalResume.aspx?categoryid=1&subjectid=1" + "&resumeid=" + info.PersonInfoId;
            //string url = WebCommon.GetApplicationPath(Request) + "Person/PersonalResume.aspx?subjectid=" + this.subjectid;
            Response.Redirect(url);
        }
    }
}